<?php

require_once './application/models/Tables/Composant.php';
require_once './application/models/Tables/Detail.php';
require_once './application/models/Tables/ConfigComposant.php';
require_once './application/models/Tables/map.php';

class ObjectComposant
{

    protected $_compo;
    protected $_lstCompo;
    protected $_map;
    protected $_lstMap;
    protected $_detail;

    public function rechercheListeComposant()
    {
        $compo = new TableComposant();
        $this->_lstCompo = $compo->getLstComposants();
        return $this->_lstCompo;
    }

    public function rechercheListeComposantDetail()
    {
        $lstCompo = $this->rechercheListeComposant();
        $lstCompoDetail = null;
        $i = 1;
        foreach ($lstCompo as $tab => $compo)
        {
            $lstCompoDetail[$i] = array($compo, $this->rechercheDetailComposant($compo['IdComposant']));
            $i++;
        }
        return $lstCompoDetail;
    }

    public function rechercheComposant($pIpComposant)
    {
        $compo = new TableComposant();
        $this->_compo = $compo->getComposant($pIpComposant);
        return $this->_compo;
    }

    public function rechercheComposantId($pIdComposant)
    {
        $compo = new TableComposant();
        $this->_compo = $compo->getComposantId($pIdComposant);
        return $this->_compo;
    }

    public function rechercheDetailComposant($pIdComposant)
    {
        $detailCompo = new TableDetail();
        $this->_detail = $detailCompo->getDetail($pIdComposant);
        return $this->_detail;
    }

    public function rechercheConfiguration($pIdComposant)
    {
        $config = new TableConfiguration();
        return $config->getConfig($pIdComposant);
    }

    public function listeToutesConfiguration()
    {
        $config = new TableConfiguration();
        return $config->getConfigAll();
    }

    public function rechercheConfigurationId($pIdConfiguration)
    {
        $config = new TableConfiguration();
        return $config->getConfigId($pIdConfiguration);
    }

    public function rechercheConfigurationDernierId($pIdConfiguration)
    {
        $config = new TableConfiguration();
        return $config->getConfigLastId($pIdConfiguration);
    }

    public function DonneComposantsPourMap($pIdMap)
    {
        $map = new TableMap();
        $lstCompo = $map->getMap($pIdMap);
        return $lstCompo;
    }

    public function DonneListeMap()
    {
        $map = new TableMap();
        $lstMap = $map->getLstMap();
        return $lstMap;
    }

    public function ajouterComposant($pNomComposant, $pIpComposant, $pNbInterface, $pTimeConnect, $pModel, $InfoDetail)
    {
        $compo = new TableComposant();
        $idCompo = $compo->addComposant($pNomComposant, $pIpComposant, $pNbInterface, $pTimeConnect, $pModel);
    }

    public function ajouterDetail($pIdComposant, $pSpeedInterface, $pMacInterface, $pIpInterface, $pMaskInterface, $pStatusInterface, $pDescriptionInterface)
    {
        $detail = new TableDetail();
        $detail->addDetail($pIdComposant, $pSpeedInterface, $pMacInterface, $pIpInterface, $pMaskInterface, $pStatusInterface, $pDescriptionInterface);
    }

    public function ajouterMap($pName, $pData)
    {
        $compo = new TableMap();
        $this->_lstCompo = $compo->addMap($pName, $pData);
    }

    public function ajouterConfiguration($pIdComposant, $pConfiguration)
    {
        $config = new TableConfiguration();
        $config->addConfig($pIdComposant, $pConfiguration);
    }

    public function supprimeDetail($pIdComposant, $pIdDetail)
    {
        $detail = new TableDetail();
        $detail->deleteDetail($pIdComposant, $pIdDetail);
    }

    public function supprimeComposant($pIdComposant)
    {
        $compo = new TableComposant();
        $compo->deleteComposant($pIdComposant);

        $lstDetail = $this->rechercheDetailComposant($pIdComposant);
        foreach ($lstDetail as $detail)
            $this->supprimeDetail($pIdComposant, $detail['IdDetail']);
    }

    public function supprimeConfiguration($pIdConfig)
    {
        $config = new TableConfiguration();
        $config->deleteConfig($pIdConfig);
    }

    public function supprimeMap($pIdMap)
    {
        $map = new TableMap();
        $map->deleteMap($pIdMap);
    }

    public function modifierComposant($pIdComposant, $pNomComposant, $pIpComposant, $pNbInterface, $pTimeConnect, $pModel)
    {
        $compo = new TableComposant();
        $compo->updateComposant($pIdComposant, $pNomComposant, $pIpComposant, $pNbInterface, $pTimeConnect, $pModel);
    }

    public function modifierDetail($pIdDetail, $pSpeedInterface, $pMacInterface, $pIpInterface, $pMaskInterface, $pStatusInterface, $pDescriptionInterface)
    {
        $detail = new TableDetail();
        $detail->updateDetail($pIdDetail, $pSpeedInterface, $pMacInterface, $pIpInterface, $pMaskInterface, $pStatusInterface, $pDescriptionInterface);
    }
}
?>